package com.example.Controller;

import com.example.Service.AiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

/**
 * 有关ai的使用接口
 */
@RestController
@RequestMapping("/ai")
public class AiController {

    @Autowired
    private AiService aiService;

    /**
     * 园课堂的ai助的正常对话
     * @param user 用户的问题
     * @return 返回ai的回答
     * @throws Exception
     */
    @PostMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter chatStream(@RequestParam String user) throws Exception {

        String prompt = "。以上是用户的提问，你需要扮演田园课堂的ai助手回答问题，且跟偏向于田园课堂的风格。";

        return aiService.vivogptStream(user ,prompt);
    }

    /**
     * ai生成古诗的功能
     * @param user 图片识别出的字段
     * @return  返回ai根据提示词搜索到的诗句
     * @throws Exception
     */
    @PostMapping(value = "/poem", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter poemStream(@RequestParam String user) throws Exception {

        String prompt = "。根据前面的提示词，写一首关于这个的唐诗";

        return aiService.vivogptStream(user,prompt);
    }

}